package bjtu.tjj.simpledy.service.impl;

import bjtu.tjj.simpledy.common.ResultCode;
import bjtu.tjj.simpledy.dto.VideoDTO;
import bjtu.tjj.simpledy.exception.CommonException;
import bjtu.tjj.simpledy.mapper.VideoDTOMapper;
import bjtu.tjj.simpledy.service.RecommendService;
import bjtu.tjj.simpledy.utils.ThreadLocalUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class RecommendServiceImpl implements RecommendService {
    private final VideoDTOMapper videoDTOMapper;

    @Override
    public List<VideoDTO> getRecommend(Integer number) {
        List<VideoDTO> videos = videoDTOMapper.getRecommend(ThreadLocalUtils.getUserId(), number);
        if (videos.isEmpty()) {
            throw new CommonException(ResultCode.NO_MORE_RECOMMEND);
        }
        return videos;
    }
}
